package com.csx.saas.platform.auth.controller;

import com.csx.basic.base.R;
import com.csx.basic.exception.BizException;
import com.csx.basic.jwt.model.AuthInfo;
import com.csx.saas.platform.auth.dto.LoginParamDTO;
import com.csx.saas.platform.auth.grant.TokenGranterBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Validated
@RestController
@RequestMapping
@AllArgsConstructor
@Api(value = "用户授权认证", tags = "登录接口")
public class AuthController {
    private final TokenGranterBuilder tokenGranterBuilder;

    @ApiOperation(value = "登录接口", notes = "登录或者刷新token时调用")
    @PostMapping(value = "/noToken/login")
    public R<AuthInfo> login(@Validated @RequestBody LoginParamDTO login) throws BizException {
        return tokenGranterBuilder.getGranter(login.getGrantType()).login(login);
    }


}
